<template>
  <div>
    <span>全选:</span>
    <input type="checkbox" v-model="isAll" />
    <button @click="fanBtn">反选</button>
    <ul>
      <li>
        <input type="checkbox" />
        {{ obj.name }}
      </li>
    </ul>
  </div>
</template>

<script>
import "bootstrap/dist/css/bootstrap.css";
import moment from "moment";
export default {
  data() {
    return {
      arr: [
        {
          name: "猪八戒",
          checked: false,
        },
        {
          name: "孙悟空",
          checked: false,
        },
        {
          name: "唐僧",
          checked: false,
        },
        {
          name: "白龙马",
          checked: false,
        },
      ],
    };
  },
  computed: {
    isAll: {
      set(val) {
        this.arr.forEach((obj) => obj.checked == val);
      },
      get() {
        return this.arr.every((obj) => obj.checked == true);
      },
    },
  },
  methods: {
    fanBtn() {
      this.arr.forEach((obj) => (obj.checked = !obj.checked));
    },
  },
};
</script>

<style>
</style>